﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureGames.Model;
using Microsoft.Practices.ServiceLocation;

namespace AzureGames.Data.InMemory
{
    public class PlayerRepository : IAIPlayerRepository, IPlayerRepository
    { 
        const string SimpleAmazonsAI = "1:BE4813EF-4A23-49FF-BDF0-8139177C9C93";
        const string Arena5Player = "2:E1694BC8-421B-4E46-B226-AEE2067C835F";

        public Model.Player GetPlayer(string playerID)
        {
           

            //var users = new UserRepository();
            IUserRepository users = new UserRepository();

            switch (playerID.ToUpper())
            {
                case SimpleAmazonsAI:
                    return new Model.AIPlayer(SimpleAmazonsAI, "SimpleAmazonsAI", "description", new Guid("B9D3E9C5-A1CD-4AB1-92C7-E84A692C9916"), 1)
                        { CreatedDate = new DateTime(2012,01,01), LastUpdatedDate = new DateTime(2012,01,01) };
                case Arena5Player:
                    return new Model.AIPlayer(Arena5Player, "SimpleEnemyShipsAI", "description", new Guid("FA28E55D-7282-4226-95A7-2FA8D4171BB9"), 2)
                        { CreatedDate = new DateTime(2012,01,01), LastUpdatedDate = new DateTime(2012,01,01) };
                case "00000000-0000-0000-0000-000000000000":
                    return new Model.AnonymousPlayer();
                default:
                    return users.GetUser(playerID);
            }
        }

        public List<Model.AIPlayer> GetAIPlayers(int gameID)
        {
            var amazonsPlayer = GetPlayer(SimpleAmazonsAI) as Model.AIPlayer;
            var arena5Player = GetPlayer(Arena5Player) as Model.AIPlayer;

            switch (gameID)
            {
                case 1:
                    return new List<Model.AIPlayer> { amazonsPlayer };
                case 2:
                    return new List<Model.AIPlayer> { arena5Player };
                default:
                    return new List<AIPlayer>();
            }
        }

        public Model.AIPlayer GetAIPlayer(string playerID)
        {
            return GetPlayer(playerID) as Model.AIPlayer;
        }


        public AzureResult AddAIPlayer(AIPlayer player)
        {
            throw new NotImplementedException();
        }

        public AzureResult UpdateAIPlayer(AIPlayer player)
        {
            throw new NotImplementedException();
        }
    }
}
